package com.xunji.user.util;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

/**
 * DateUtil
 *
 * @author ruiwu3@iflytek.com
 * @version 2017年7月10日 下午5:07:18
 * @since 0.1
 */
public class DateUtil {


    private DateUtil() {
        throw new IllegalStateException("Utility class");
    }

    /**
     * 获取当前时间前一天时间戳
     */
    public static long getLastDayDateTime() {

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.DAY_OF_MONTH, -1);

        return calendar.getTime().getTime();
    }


    public static String getTimeStampStr(LocalDateTime localDateTime) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHH:mm:ss");
        return formatter.format(localDateTime);
    }

    public static String getTimeStampStr() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return formatter.format(LocalDateTime.now());
    }

    public static String currentTime() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        return formatter.format(LocalDateTime.now());
    }

    public static String getDateTime() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmm");
        // 获取当前时间
        Date now = new Date();
        // 格式化当前时间
        return formatter.format(now);
    }

    public static void main(String[] args) {
        System.out.println(getTimeStampStr(LocalDateTime.now()));
    }

}
